package com.LostAndFound.service;

import java.sql.SQLException;
import java.util.List;

import com.LostAndFound.dao.MeDao;
import com.LostAndFound.domain.SystemInfo;
import com.LostAndFound.domain.User;
import com.LostAndFound.utils.DataSourceUtils;

public class MeService {
	MeDao dao = new MeDao();

	public boolean editMyInfo(User user) {
		boolean success = false;
		try {
			DataSourceUtils.startTransaction();
			dao.editMyInfo(user);
			success = true;
		} catch (SQLException e) {
			try {
				DataSourceUtils.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			try {
				DataSourceUtils.commitAndRelease();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return success;
	}
	
	public User findUserToSession(String uid) {
		User user = null;
		try {
			user = dao.findUserToSession(uid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	public boolean updatePassword(String uid, String newPassword) {
		boolean success = false;
		try {
			dao.updatePassword(uid,newPassword);
			success = true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return success;
	}
	public List<SystemInfo> getSystemInfoList() {
		List<SystemInfo> systemInfoList = null;
		try {
			systemInfoList = dao.getSystemInfoList();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return systemInfoList;
	}
	public SystemInfo showSystemInfoDetailByInfoId(String infoid) {
		SystemInfo systemInfo = new SystemInfo();
		try {
			systemInfo = dao.showSystemInfoDetailByInfoId(infoid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return systemInfo;
	}
}
